package homework.homework_7.Enter;

import java.util.ArrayList;

/**
 * @author 朱
 * @date 201904018:59
 */
public class UserDaoImp implements UserDao{
    static ArrayList<User> arrayList=new ArrayList<User>();
    @Override
    public void regist(User user) {
            if (arrayList.contains(user)){
                System.out.println("注册失败");
            }else {
                System.out.println("注册成功");
                arrayList.add(user);
            }
    }

    @Override
    public boolean login(String user, String password) {
        for (int i = 0; i <arrayList.size() ; i++) {
            if (arrayList.get(i).getUser().equals(user)&&arrayList.get(i).getPassword().equals(password)){
                System.out.println("登陆成功");
                return true;
            }else {
                System.out.println("登陆失败");
                return false;
            }
        }
        return false;
    }

    @Override
    public boolean search(String user) {
        for (int i = 0; i <arrayList.size() ; i++) {
            if (arrayList.get(i).getUser().equals(user)){
                System.out.println(arrayList.get(i));
                return true;
            }else {
                System.out.println("搜索用户不存在");
                return false;
            }
        }
        return false;
    }
}
